package com.zxl.always.on.display.ui.widget.clock.analog;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zxl.always.on.display.R;
import com.zxl.always.on.display.ui.widget.clock.StandAloneClock;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * Created by Administrator on 2018/3/1.
 */

public class AnalogClockWidget extends LinearLayout implements StandAloneClock, AnalogClockDrawingView.OnTimerUpdateListener {

    private TextView mCalendarView;

    private AnalogClockDrawingView mClockView;

    public AnalogClockWidget(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mClockView = findViewById(R.id.analog_clock_view);
        mCalendarView = findViewById(R.id.panel_clock_calendar);
    }

    @Override
    public void pauseStandAloneMode() {
        mClockView.pauseStandAloneMode();
    }

    @Override
    public void refreshTime() {
        mClockView.refreshTime();
        onUpdate();
    }

    @Override
    public void resumeStandAloneMode() {
        mClockView.resumeStandAloneMode();
    }

    @Override
    public void setStandAloneMode(boolean isStandAlone) {
        mClockView.setStandAloneMode(isStandAlone);
    }

    @Override
    public void setPaletteColor(int position) {
        mClockView.setPaletteColor(position);
    }

    @Override
    public void onUpdate() {
        SimpleDateFormat dateFormat = new SimpleDateFormat(getResources().getString(R.string.calendar_date_full_format), Locale.getDefault());
        Date date = Calendar.getInstance().getTime();
        mCalendarView.setText(dateFormat.format(date));
    }

    @Override
    public void setBackgroundStyle(int position) {
    }
}
